package controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import db.DbConn;

public class GiveUp extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	DbConn conn;

	@Override
	public void init() throws ServletException {
		conn = new DbConn();
		conn.setDbUrl(getServletContext().getInitParameter("dbUrl"));
		conn.setDbUser(getServletContext().getInitParameter("dbUser"));
		conn.setDbPass(getServletContext().getInitParameter("dbPass"));
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		process(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		process(req, resp);
	}

	protected void process(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		String userid = (String)session.getAttribute("userId");
		conn.giveUpCurrentProject(userid);
		
		resp.setContentType("text/html");
		resp.setCharacterEncoding("UTF-8");
		PrintWriter out = resp.getWriter();
		out.println("<script type='text/javascript'>");
		out.println("alert('현재까지의 진행상황을 완료목록으로 옮겼습니다.');");
		out.println("location.href='logonIndex.jsp';");
		out.println("</script>");
		out.flush();
		
	}
}
